<?php


require_once "objetos/Usuario.php";
require_once "objetos/Email.php";
require_once "server/EmailServer.php";

session_start();
if(!array_key_exists("userId", $_SESSION) && $_SESSION["userId"] == NULL){
    head("Location: ../index.php");
}
$userId = $_SESSION["userId"];
$idEmail = $_GET["idEmail"];

$emailServer = new EmailServer();
$conn = $emailServer->imapOpen($userId->getLogin(), $userId->getSenha());
$emailImapHeader = $emailServer->obterInfoEmail($conn, $idEmail);
$emailImapContent = $emailServer->obterConteudoEmail($conn, $idEmail);


$email = new Email();
$email->setAssunto("Re: ".$emailImapHeader[0]->subject);
$from = explode('"',$emailImapHeader[0]->from);
$email->setDestinatario($from[1]);
$email->setConteudo("\n\n------------------------------\n".$emailImapContent);

$emailServer->imapClose($conn);

$_SESSION["email"] = $email;
header("Location: ../paginas/responderEmail.php");

?>
